package com.itheima.hz.controller;

import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping(path = "/ai")
@RequiredArgsConstructor
public class ChatController {
    private  final ChatClient chatClient;

    // 普通调用
    /*@GetMapping(path = "/chat",produces = "text/html;charset=UTF-8")
    public String chat(@RequestParam("prompt") String prompt) {
        return chatClient.prompt(prompt)
                .call()
                .content();
    }*/

    // 流式调用
    @GetMapping(path = "/chat",produces = "text/html;charset=UTF-8")
    public Flux<String> chat(@RequestParam("prompt") String prompt) {
        return chatClient.prompt(prompt)
                .stream()
                .content();
    }
}
